<!DOCTYPE HTML>
<html>
<head>
<title>#MaxThreads | AutoHotkey</title>
<meta name="description" content="The #MaxThreads directive sets the maximum number of simultaneous threads." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>#MaxThreads</h1>

<p>设置可同时存在的<a href="../misc/Threads.htm">线程</a>的最大数目.</p>

<pre class="Syntax"><span class="func">#MaxThreads</span> Value</pre>
<h2>参数</h2>
<dl>

  <dt>Value</dt>
  <dd><p>可以同时存在的最大<a href="../misc/Threads.htm">线程</a>数. 指定大于 255 的数字相当于指定 255(在 1.0.48 之前的版本中, 此限制为 20).</p></dd>

</dl>
<h2>备注</h2>
<p>此设置是全局的, 这意味着只需要使用一次(在脚本的任意位置) 就会影响整个脚本.</p>
<p>尽管可以把这个值设置为 1, 但不建议这么做, 因为每当脚本显示 <a href="MsgBox.htm">MsgBox</a> 或其他对话框时会阻止新的<a href="../Hotkeys.htm">热键</a>运行. 在其他<a href="../misc/Threads.htm">线程</a>休眠或等待时还会阻止<a href="SetTimer.htm">计时器</a>运行.</p>
<p>在达到 #MaxThreads 的限制后, 最多可以创建两个下列类型的<a href="../misc/Threads.htm">线程</a>: 子程序的首行为 <a href="ExitApp.htm">ExitApp</a>, <a href="Pause.htm">Pause</a>, <a href="Edit.htm">Edit</a>, <a href="Reload.htm">Reload</a>, <a href="KeyHistory.htm">KeyHistory</a>, <a href="ListLines.htm">ListLines</a>, <a href="ListVars.htm">ListVars</a> 或 <a href="ListHotkeys.htm">ListHotkeys</a> 的<a href="../Hotkeys.htm">热键</a>, <a href="../Hotstrings.htm">热字串</a>, <a href="../misc/Clipboard.htm#OnClipboardChange">OnClipboardChange</a> 或 <a href="Gui.htm#Events">GUI 事件</a>. 而且, 不管存在多少个线程 <a href="OnExit.htm">OnExit 子程序</a>总是会运行.</p>
<p>如果此设置小于 <a href="_MaxThreadsPerHotkey.htm">#MaxThreadsPerHotkey</a>, 那么它会覆盖那个设置.</p>
<p>如果脚本中未使用此指令, 那么它会表现的就像此设置为 10 那样.</p>
<h2>相关</h2>
<p><a href="_MaxThreadsPerHotkey.htm">#MaxThreadsPerHotkey</a>, <a href="../misc/Threads.htm">线程</a>, <a href="_MaxHotkeysPerInterval.htm">#MaxHotkeysPerInterval</a>, <a href="_HotkeyInterval.htm">#HotkeyInterval</a>, <a href="ListHotkeys.htm">ListHotkeys</a>, <a href="_MaxMem.htm">#MaxMem</a></p>
<h2>示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>#MaxThreads 2</pre>
</div>

</body>
</html>